home *** CD-ROM | disk | FTP | other *** search
/ CD Actual 22 / PC Actual CD 22.iso / SHARE / prog / POVRAY / NKFLARE.ZIP / NKFlare.inc < prev    next >
Encoding:
Text File  |  1997-09-04  |  52.3 KB  |  1,421 lines

  1. //
  2. //             N K F l a r e . I N C
  3. //   ------------------------------------------
  4. //
  5. //      Lens Flare "plug-in" for POV-RAY 3.0
  6. //
  7. //    Copyright (C) 1997           Nathan Kopp
  8. //
  9. //    Version 4.0                 August, 1997
  10. //
  11. //   ------------------------------------------
  12. //
  13. //    Documentation for NKFlare is in the file
  14. //    NKFlare.TXT.  NKFlare.TXT must accompany
  15. //    NKFlare.INC in all distributions.
  16. //
  17. // NKFlare is a very flexible lens flare include file for POV-Ray 3.0.
  18. //
  19. // Adding lens flare to your POV scene is now a simple as adding the
  20. // following few lines to your scene description file:
  21. //
  22. //  #declare cam_loc = <x,y,z>    // use the x, y, and z of your camera
  23. //  #declare light_loc = <x,y,z>  // use the x, y, and z of the light
  24. //                                // you wish to flare
  25. //  #declare lookat = <x,y,z>     // the look_at vector of your camera
  26. //  #declare sky_vect = <x,y,z>   // the sky vector of your camera
  27. //  #include "35mm.flr"           // or whatever pre-defined flare you like
  28. //  #include "NKFlare.inc"        // create the lens flare
  29. //
  30. //   ------------------------------------------
  31.  
  32. #declare no_lens_flare = false  // ** assume no problems
  33.  
  34. #ifndef (cam_loc)
  35.   #warning "You need to specify a camera location (cam_loc) for lens flare.\n"
  36.   #declare no_lens_flare = true
  37. #end
  38.  
  39. #ifndef (light_loc)
  40.   #warning "You need to specify a light location (light_loc) for lens flare.\n"
  41.   #declare no_lens_flare = true
  42. #end
  43.  
  44. #ifndef (lookat)
  45.   #warning "You need to specify a look_at location (lookat) for lens flare.\n"
  46.   #declare no_lens_flare = true
  47. #end
  48.  
  49. // *****************************************************************
  50. // ** for older files that had '#declare moray = yes'
  51. // ** instead of '#declare CoordSys = "moray"'
  52. //
  53. // ** Note: CoordSys only effects default sky_vect
  54. // *****************************************************************
  55. #ifdef(moray) #if(moray) #declare CoordSys = "moray" #end #end
  56. #ifndef (CoordSys) #declare CoordSys = "pov" #end
  57. #declare CoordSys = strlwr(CoordSys)      // CoordSys is case insensitive
  58.  
  59. #ifndef (sky_vect)
  60.   #if (CoordSys = 'moray')
  61.     #declare sky_vect = <0,0,1>
  62.   #else
  63.     #declare sky_vect = <0,1,0>
  64.   #end
  65. #end
  66.  
  67.  
  68. #if (no_lens_flare = false)
  69.  
  70. // *****************************************************************
  71. // ******** ALL'S OK.... CONTINUE WITH LENS FLARE ******************
  72. // *****************************************************************
  73.  
  74. // if they defined "flare_type" and it is not blank, then
  75. // use it for the include filename
  76. //
  77. #ifdef (flare_type)
  78.   #if (strlen(flare_type)>0)
  79.     #if (strcmp(flare_type, "camcorder")=0)
  80.       #include "camcordr.flr"
  81.     #else #if (strcmp(flare_type, "smallstar")=0)
  82.       #include "smlstar.flr"
  83.     #else #if (strcmp(flare_type, "warpflare")=0)
  84.       #include "warp.flr"
  85.     #else
  86.       #declare filename = concat(flare_type,".flr")
  87.       #if (file_exists(filename))
  88.         #include filename
  89.       #else
  90.         #debug concat("Could not find the file: ",filename)
  91.         #debug "\n"
  92.       #end
  93.     #end #end #end
  94.   #end
  95. #end
  96.  
  97. // *****************************************************************
  98. // ** set flare_amount and flare_brightness if the user specifies
  99. // ** a bright background
  100. //
  101. #ifdef (bright_background)
  102.   #if (bright_background)
  103.     #ifndef (flare_amount)     #declare flare_amount     = 0.4 #end
  104.     #ifndef (flare_brightness) #declare flare_brightness = 1.5 #end
  105.   #end
  106. #end
  107.  
  108. // *****************************************************************
  109. // ** Additional rotation degrees.
  110. //
  111. #ifndef (flare_rotate) #declare flare_rotate = 0 #end
  112. #ifndef (flare_auto_rotate) #declare flare_auto_rotate = false #end
  113. #ifndef (spots_auto_rotate) #declare spots_auto_rotate = false #end
  114.  
  115. // *****************************************************************
  116. // ** sizes for primary flare
  117. //
  118. #ifndef (source_size) #declare source_size = .02 #end
  119. #ifndef (glow_size)   #declare glow_size   = .15 #end
  120. #ifndef (ring_size)   #declare ring_size   = .3 #end
  121. #ifndef (ring_width)  #declare ring_width  = .1 #end
  122.  
  123. // *****************************************************************
  124. // ** colors for primary flare
  125. //
  126. #ifndef (source_color)  #declare source_color  = <1, 1, 1> #end
  127. #ifndef (glow_color)    #declare glow_color    = <1, 1, .7> #end
  128. #ifndef (ring_color)    #declare ring_color    = <1, .7, .7> #end
  129. #ifndef (source_bright) #declare source_bright = 2 #end
  130. #ifndef (glow_bright)   #declare glow_bright   = 1.2 #end
  131.  
  132. // *****************************************************************
  133. // ** translucencies for primary flare
  134. //
  135. #ifndef (source_tr)   #declare source_tr   = .1 #end
  136. #ifndef (glow_tr)     #declare glow_tr     = .7 #end
  137. #ifndef (ring_tr)     #declare ring_tr     = .8 #end
  138. #ifndef (source_fade) #declare source_fade = .20 #end
  139.  
  140. // *****************************************************************
  141. // ** attributes for big_glow
  142. //
  143. #ifndef (big_glow_size)  #declare big_glow_size  = 0 #end
  144. #ifndef (big_glow_color) #declare big_glow_color = <1,1,1> #end
  145. #ifndef (big_glow_tr)    #declare big_glow_tr    = 1 #end
  146.  
  147. // *****************************************************************
  148. // ** attributes for streaks
  149. //
  150. #ifndef (streak_a_size) #declare streak_a_size = 0 #end
  151. #ifndef (streak_b_size) #declare streak_b_size = 0 #end
  152. #ifndef (streak_a_tr)   #declare streak_a_tr   = 1 #end
  153. #ifndef (streak_b_tr)   #declare streak_b_tr   = 1 #end
  154.  
  155. // *****************************************************************
  156. // ** default scale factors
  157. //
  158. #ifndef (main_flare_scale) #declare main_flare_scale = <1,1,1> #end
  159. #ifndef (big_glow_scale)   #declare big_glow_scale = <1,1,1> #end
  160.  
  161. // *****************************************************************
  162. // ** attributes for star (sparkle)
  163. //
  164. #ifndef (star_color)  #declare star_color = <1,1,1> #end
  165. #ifndef (star_tr)     #declare star_tr    = .9 #end
  166. #ifndef (star_size)   #declare star_size  = .2 #end
  167. #ifndef (star_size2)  #declare star_size2 = star_size / 2 #end
  168. #ifndef (num_arms)    #declare num_arms   = 9 #end
  169. #ifndef (num_arms2)   #declare num_arms2  = 9*2 #end
  170. #ifndef (star_width)  #declare star_width = .1 #end
  171. #ifndef (star_width2) #declare star_width2= .05 #end
  172. #ifndef (star_rand)   #declare star_rand  = 0 #end
  173. #ifndef (star_rand2)  #declare star_rand2 = 0 #end
  174. #ifndef (star_seed) #declare star_seed = seed(55) #end
  175.  
  176. #ifndef (star_mirror) #declare star_mirror = true #end
  177. #ifndef (star_spread) #declare star_spread = true #end
  178. #ifndef (crisp_star)  #declare crisp_star  = false #end
  179. #ifndef (star_color_rand) #declare star_color_rand = 0 #end
  180. #ifndef (star_size_rand) #declare star_size_rand = 0 #end
  181.  
  182. // *****************************************************************
  183. // ** attributes for spots
  184. //
  185. #ifndef (num_spots)      #declare num_spots     = 4 #end
  186. #ifndef (opposite_spots) #declare opposite_spots= 4 #end
  187. #ifndef (skip_spots)     #declare skip_spots    = 1 #end
  188. #ifndef (spot_dist)      #declare spot_dist     = .2 #end
  189. #ifndef (spot_dist_pwr)  #declare spot_dist_pwr = 2 #end
  190. #ifndef (percent_dots)   #declare percent_dots    = 0 #end
  191. #ifndef (percent_hex)    #declare percent_hex     = 0 #end
  192. #ifndef (percent_pent)   #declare percent_pent    = 0 #end
  193.  
  194. #ifndef (spot_size)     #declare spot_size     = .1 #end
  195. #ifndef (spot_color)    #declare spot_color    = <1,1,.7> #end
  196. #ifndef (spot_tr)       #declare spot_tr       = .9 #end
  197.  
  198. #ifndef (dot_size)      #declare dot_size      = .04 #end
  199. #ifndef (dot_color)     #declare dot_color     = <.4,1,.5> #end
  200. #ifndef (dot_tr)        #declare dot_tr        = .75 #end
  201.  
  202. // *****************************************************************
  203. // ** randomness for spots
  204. //
  205. #ifndef (spot_seed)       #declare spot_seed       = seed(546) #end
  206. #ifndef (spot_dist_rand)  #declare spot_dist_rand  = 0 #end
  207.  
  208. #ifndef (spot_size_rand)  #declare spot_size_rand  = 1 #end
  209. #ifndef (spot_color_rand) #declare spot_color_rand = 0 #end
  210. #ifndef (dot_size_rand)   #declare dot_size_rand   = 1 #end
  211. #ifndef (dot_color_rand)  #declare dot_color_rand  = 0 #end
  212. #ifndef (spot_fade_amount)#declare spot_fade_amount= 0 #end
  213.  
  214. // *****************************************************************
  215. // ** Don't show flare source if they don't want us to
  216. // *****************************************************************
  217. #ifdef (show_flare_source) #if (show_flare_source = no)
  218.    #declare source_tr = glow_tr
  219. #end #end
  220.  
  221. // *****************************************************************
  222. // ** this is the size of the sphere that's around the camera
  223. // *****************************************************************
  224. #ifndef (disc_size)
  225.   #ifdef (sphere_size)
  226.     #declare disc_size = sphere_size
  227.   #else
  228.     #declare disc_size = .001
  229.   #end
  230. #end
  231.  
  232. // *****************************************************************
  233. // ** this is the scaling factor of the entire scene
  234. // *****************************************************************
  235. #ifndef (flare_size)
  236.   #ifdef (flare_scale_factor)
  237.     #declare flare_size = flare_scale_factor
  238.   #else
  239.     #declare flare_size = 1
  240.   #end
  241. #end
  242. #ifndef (AmbientLight) #declare AmbientLight = <1,1,1> #end
  243.  
  244. // *****************************************************************
  245. // ************ DECLARE TRANSFORM VARIABLES ********************
  246. // *****************************************************************
  247.  
  248. // *****************************************************************
  249. // ** compute relative location of camera to light source
  250. // ** compute relative location of camera to center
  251. // *****************************************************************
  252. #declare lf_2light = cam_loc - light_loc
  253. #declare lf_2ctr = cam_loc - lookat
  254.  
  255. // Now project lf_2light onto lf_2ctr to find new lf_2ctr vector.  This gives us
  256. // a vector from cam_loc to lf_2ctr that is perpendecular to the relative
  257. // lookat vector.  The newctr vector is used in for multiple flare
  258. // spot calculation.
  259. #declare lf_newctr = lf_2ctr * vdot(lf_2light,lf_2ctr) / (vlength(lf_2ctr)*vlength(lf_2ctr))
  260.  
  261. // *****************************************************************
  262. // ** This hides the flare if it goes behind a planet
  263. // *****************************************************************
  264. #ifdef (planet_rad) #ifdef (light_rad) #ifdef (planet_loc)
  265.   #declare lf_2planet = cam_loc - planet_loc
  266.  
  267.   // *****************************************************************
  268.   // ** Don't hide if light is in front of planet
  269.   // *****************************************************************
  270.   #if (vlength(lf_2light) > vlength(lf_2planet))
  271.  
  272.      #declare lf_2light_p = lf_2light * vdot(lf_2planet,lf_2light) / (pow(vlength(lf_2light),2))
  273.      #declare light_rad = light_rad * vlength(lf_2light_p) / vlength(lf_2light)
  274.  
  275.      #declare lf_temp_vect = vnormalize(lf_2light_p) - vnormalize(lf_2light)
  276.      // *****************************************************************
  277.      // ** Careful -- don't hide if planet is on other side of camera
  278.      // *****************************************************************
  279.      #if ((lf_temp_vect.x = 0) & (lf_temp_vect.y = 0) & (lf_temp_vect.z = 0))
  280.  
  281.         #declare lf_h = vlength(lf_2light_p - lf_2planet)
  282.         #if (lf_h > (planet_rad + light_rad))
  283.           #declare lf_visible = 1
  284.           #declare lf_transmit = 0
  285.         #else #if ( lf_h+light_rad < planet_rad )
  286.           #declare lf_visible = 0
  287.           #declare lf_transmit = 1
  288.         #else
  289.           #declare lf_area = pi*pow(light_rad,2)
  290.  
  291.           #declare lf_x = ( pow(planet_rad,2) - pow(light_rad,2) + lf_h*lf_h ) / (2*lf_h)
  292.           #declare lf_y = sqrt( pow(planet_rad,2) - lf_x*lf_x )
  293.           #declare lf_theta = atan2(lf_y,lf_x)
  294.           #declare lf_area1 = pow(planet_rad,2) * lf_theta - lf_x*lf_y
  295.  
  296.           #declare lf_x = lf_h - lf_x
  297.           #declare lf_y = sqrt( pow(light_rad,2) - lf_x*lf_x )
  298.           #declare lf_theta = atan2(lf_y,lf_x)
  299.           #declare lf_area2 = lf_area * lf_theta/pi - lf_x*lf_y
  300.  
  301.           #declare lf_visible = (lf_area - (lf_area1+lf_area2)) / lf_area
  302.           #declare lf_transmit = 1-lf_visible
  303.  
  304.           #declare lf_intersect = vnormalize(lf_2light_p-lf_2planet) * lf_h
  305.           #declare lf_vradius = (lf_2light_p-lf_2planet) + vnormalize(lf_2light_p-lf_2planet) * light_rad
  306. // the following line was causing problems, so it was removed until I can debug it.  :(
  307. //          #declare lf_2light = lf_2planet + lf_intersect + (lf_vradius - lf_intersect) * pow(lf_transmit,2)
  308.         #end #end
  309.  
  310.         #warning "\n"
  311.         #warning "Percent of light visible is: "
  312.         #warning str(lf_visible*100,5,0)
  313.         #warning "\n"
  314.  
  315.         #ifdef(flare_shrink) #if (flare_shrink = true)
  316.           #declare flare_size = flare_size * pow((1-lf_transmit/2),.5)
  317.         #end #end
  318.  
  319.         #if (lf_transmit = 1) #declare no_lens_flare = true #end
  320.  
  321.         #declare star_tr = star_tr + (1-star_tr) * pow(lf_transmit,2)
  322.         #declare glow_tr = glow_tr + (1-glow_tr) * pow(lf_transmit,2)
  323.         #declare ring_tr = ring_tr + (1-ring_tr) * pow(lf_transmit,2)
  324.         #declare source_tr = source_tr + (1-source_tr) * pow(lf_transmit,2)
  325.         #declare spot_tr = spot_tr + (1-spot_tr) * pow(lf_transmit,2)
  326.         #declare dot_tr = dot_tr + (1-dot_tr) * pow(lf_transmit,2)
  327.         #declare big_glow_tr = big_glow_tr + (1-big_glow_tr) * pow(lf_transmit,2)
  328.      #end
  329.    #end
  330. #end #end #end
  331.  
  332. // *****************************************************************
  333. // ** This hides the flare if it below a plane
  334. // *****************************************************************
  335. #ifdef (plane_loc) #ifdef (plane_norm) #ifdef (light_rad)
  336.   #declare lf_to_plane = cam_loc - plane_loc
  337.   #declare lf_area = pi*light_rad*light_rad
  338.  
  339.   // *****************************************************************
  340.   //  Plane equation:   a(x-x0) + b(y-y0) + c(z-z0) = 0
  341.   //  To find if light is on same side of plane as camera
  342.   // *****************************************************************
  343.   #declare lf_hide_plane = vdot( (lf_2light-lf_to_plane), plane_norm)
  344.   #declare lf_hide_plane = lf_hide_plane / abs(lf_hide_plane)
  345.  
  346.   #declare lf_hide_plane2 = vdot( lf_to_plane, plane_norm)
  347.   #declare lf_hide_plane2 = lf_hide_plane2 / abs(lf_hide_plane2)
  348.   #if (lf_hide_plane2 > 0) #declare plane_norm = - plane_norm #end  // put camera on proper
  349.                                                                     // side of plane
  350.   #declare lf_hide_plane = lf_hide_plane - lf_hide_plane2
  351.     // *****************************************************************
  352.     //  zero = opposite sides, not zero = same side
  353.  
  354.   #declare lf_b_vector = lf_2light - lf_to_plane
  355.   #declare lf_d = abs( vdot(plane_norm, lf_b_vector) ) / vlength(plane_norm)
  356.  
  357.   // *****************************************************************
  358.   // ** set up area percents and top area percents
  359.   // *****************************************************************
  360.   #if ((lf_d < light_rad) & (lf_d != 0))
  361.     #declare lf_x = sqrt( light_rad*light_rad - lf_d*lf_d)
  362.     #declare lf_theta = atan2(lf_x, lf_d)
  363.     #declare lf_a_pie = light_rad*light_rad * lf_theta
  364.     #declare lf_a_tri = lf_x * lf_d
  365.  
  366.     #if (lf_hide_plane = 0)  // ** other side
  367.       #declare lf_area_per = (lf_a_pie - lf_a_tri) / lf_area
  368.       #declare lf_top_area = pi * lf_x*lf_x / lf_area
  369.     #else                    // ** same side
  370.       #declare lf_area_per = (lf_area - lf_a_pie + lf_a_tri) / lf_area
  371.       #declare lf_top_area = 1.00
  372.     #end
  373.   #else
  374.     #if (lf_d = 0)
  375.       #declare lf_area_per = .50
  376.       #declare lf_top_area = 1.00
  377.     #else  // d>r
  378.       #if (lf_hide_plane = 0)  // ** other side
  379.         #declare lf_area_per = 0.0
  380.         #declare lf_top_area = 0.00
  381.       #else                    // ** same side
  382.         #declare lf_area_per = 1.0
  383.         #declare lf_top_area = 1.00
  384.       #end
  385.     #end
  386.   #end
  387.  
  388.   #declare lf_theta = degrees (acos(vdot(-plane_norm,lf_2light) / (vlength(-plane_norm)*vlength(lf_2light))))
  389.   #declare lf_theta = min(lf_theta,90)
  390.   #declare lf_theta_per = lf_theta / 90
  391.  
  392.   #declare lf_visible = lf_top_area + (lf_area_per - lf_top_area) * lf_theta_per
  393.  
  394.   #if (lf_hide_plane = 0)  // ** other side
  395.     #declare lf_2light = lf_2light + ((light_rad - lf_d)/4 + lf_d )*vnormalize(plane_norm)
  396.   #else                    // ** same side
  397.     #declare lf_2light = lf_2light + ((light_rad - lf_d)/4 )*vnormalize(plane_norm)
  398.   #end
  399.  
  400.   #warning "\n"
  401.   #warning "Percent of light visible is: "
  402.   #warning str(lf_visible*100,5,0)
  403.   #warning "\n"
  404.  
  405.   #declare lf_transmit = 1 - lf_visible
  406.  
  407.   #ifdef(flare_shrink) #if (flare_shrink = true)
  408.     #declare flare_size = flare_size * pow((1-lf_transmit/2),.5)
  409.   #end #end
  410.  
  411.   #if (lf_transmit = 1) #declare no_lens_flare = true #end
  412.  
  413.   #declare star_tr = star_tr + (1-star_tr) * pow(lf_transmit,2)
  414.   #declare glow_tr = glow_tr + (1-glow_tr) * pow(lf_transmit,2)
  415.   #declare ring_tr = ring_tr + (1-ring_tr) * pow(lf_transmit,2)
  416.   #declare source_tr = source_tr + (1-source_tr) * pow(lf_transmit,2)
  417.   #declare spot_tr = spot_tr + (1-spot_tr) * pow(lf_transmit,2)
  418.   #declare dot_tr = dot_tr + (1-dot_tr) * pow(lf_transmit,2)
  419.   #declare big_glow_tr = big_glow_tr + (1-big_glow_tr) * pow(lf_transmit,2)
  420.  
  421. #end #end #end
  422.  
  423.  
  424. #ifdef (flare_amount)
  425.    #declare lf_transmit = 1 - flare_amount
  426.    #if (lf_transmit = 1) #declare no_lens_flare = true #end
  427.  
  428.    #declare star_tr = star_tr + (1-star_tr) * pow(lf_transmit,1)
  429.    #declare glow_tr = glow_tr + (1-glow_tr) * pow(lf_transmit,1)
  430.    #declare ring_tr = ring_tr + (1-ring_tr) * pow(lf_transmit,1)
  431.    #declare source_tr = source_tr + (1-source_tr) * pow(lf_transmit,1)
  432.    #declare spot_tr = spot_tr + (1-spot_tr) * pow(lf_transmit,1)
  433.    #declare dot_tr = dot_tr + (1-dot_tr) * pow(lf_transmit,1)
  434.    #declare big_glow_tr = big_glow_tr + (1-big_glow_tr) * pow(lf_transmit,1)
  435. #end
  436.  
  437. // *****************************************************************
  438. // ** compute rotation values for x and z axes
  439. // *****************************************************************
  440. #declare lf_2ctr = -lf_2ctr    #declare lf_2light = -lf_2light
  441.  
  442. // ** project z onto lf_2ctr and subtract from z
  443. #declare lf_newz = z - lf_2ctr * vdot(z,lf_2ctr) / pow(vlength(lf_2ctr),2)
  444. #declare lf_newz = vnormalize(lf_newz)
  445.  
  446. #declare lf_point_up = sky_vect - lf_2ctr * vdot(sky_vect,lf_2ctr) / pow(vlength(lf_2ctr),2)
  447. #declare lf_point_ctr = lf_2light - lf_2ctr * vdot(lf_2light,lf_2ctr) / pow(vlength(lf_2ctr),2)
  448.  
  449. // ** cross newz and lf_2ctr to get a vector perpendicular to both
  450. #declare lf_perp = vcross(lf_2ctr,lf_newz)
  451.  
  452. // ************************************
  453. // ** Compute rotate towards sky vector
  454. // ** project sky_vect onto perp
  455. #declare lf_cdir = lf_perp * vdot(lf_point_up,lf_perp) / pow(vlength(lf_perp),2)
  456.  
  457. #declare lf_rotate_up = z*degrees(acos(vdot(lf_point_up,lf_newz)/vlength(lf_point_up)))
  458. #if (lf_cdir.x <= 0) #declare lf_rotate_up = -lf_rotate_up #end
  459.  
  460. // ************************************
  461. // ** Compute rotate towards center
  462. // ** project sky_vect onto perp
  463. #declare lf_cdir = lf_perp * vdot(lf_point_ctr,lf_perp) / pow(vlength(lf_perp),2)
  464.  
  465. #declare lf_rotate_ctr = z*degrees(acos(vdot(lf_point_ctr,lf_newz)/vlength(lf_point_ctr)))
  466. #if (lf_cdir.x <= 0) #declare lf_rotate_ctr = -lf_rotate_ctr #end
  467.  
  468. #declare lf_rotate_x = -x*degrees(acos(vdot(lf_2ctr,z)/vlength(lf_2ctr)))
  469. #declare lf_rotate_z = -z*degrees(atan2(lf_2ctr.x,lf_2ctr.y))
  470.  
  471. #declare lf_2ctr = -lf_2ctr    #declare lf_2light = -lf_2light
  472.  
  473.  
  474. // *****************************************************************
  475. // ** randoms are relative to their respective variables
  476. // *****************************************************************
  477. #declare spot_dist_rand = spot_dist_rand * spot_dist
  478. #declare spot_size_rand = spot_size_rand * spot_size
  479. #declare dot_size_rand  = dot_size_rand * dot_size
  480. #declare star_size_rand = star_size_rand * star_size
  481.  
  482. // *****************************************************************
  483. // ** set up lf_StarTex and lf_StarTex2 for the two sparkle textures
  484. // *****************************************************************
  485.  
  486. #declare lf_temp_tr = 1.0
  487. #if (crisp_star = true) #declare lf_temp_tr = star_tr #end
  488.  
  489. #if (num_arms > 0)
  490. #declare lf_StarTex = pigment {
  491.   radial
  492.  
  493.   #if (star_mirror = true)
  494.     frequency 2
  495.     #declare lf_tmp_width = star_width / num_arms * 2
  496.     #declare lf_ave_dist  = 1 / num_arms * 2
  497.   #else
  498.     frequency 1
  499.     #declare lf_tmp_width = star_width / num_arms
  500.     #declare lf_ave_dist  = 1 / num_arms
  501.   #end
  502.   
  503.   #declare lf_loc = 0
  504.  
  505.   color_map{
  506.     [0.0          color star_color transmit star_tr   ]
  507.     [lf_tmp_width color star_color transmit lf_temp_tr]
  508.     [lf_tmp_width color star_color transmit 1.0       ]
  509.  
  510.     #declare lf_loc = lf_loc +  lf_ave_dist + (rand(star_seed)*2 - 1)*star_rand*(lf_ave_dist-2*lf_tmp_width)
  511.     #while (lf_loc <(1-2*lf_tmp_width))
  512.       #declare lf_s_color = star_color + star_color_rand * <(rand(star_seed) * 2 - 1),(rand(star_seed) * 2 - 1),(rand(spot_seed) * 2 - 1)>
  513.       [lf_loc - lf_tmp_width  color lf_s_color transmit 1.0       ]
  514.       [lf_loc - lf_tmp_width  color lf_s_color transmit lf_temp_tr]
  515.       [lf_loc                 color lf_s_color transmit star_tr   ]
  516.       [lf_loc + lf_tmp_width  color lf_s_color transmit lf_temp_tr]
  517.       [lf_loc + lf_tmp_width  color lf_s_color transmit 1.0       ]
  518.       #declare lf_loc = lf_loc +  lf_ave_dist + (rand(star_seed)*2 - 1)*star_rand*(lf_ave_dist-2*lf_tmp_width)
  519.     #end
  520.  
  521.     [1-lf_tmp_width color star_color transmit 1.0       ]
  522.     [1-lf_tmp_width color star_color transmit lf_temp_tr]
  523.     [1.0            color star_color transmit star_tr   ]
  524.   }
  525.  
  526.  rotate <90,0,-90>
  527. }
  528. #end
  529.  
  530. #if (num_arms2 > 0)
  531. #declare lf_StarTex2 = pigment {
  532.   radial
  533.   #if (star_mirror = true)
  534.     frequency 2
  535.     #declare lf_tmp_width = star_width2 / num_arms2 * 2
  536.     #declare lf_ave_dist  = 1 / num_arms2 * 2
  537.   #else
  538.     frequency 1
  539.     #declare lf_tmp_width = star_width2 / num_arms2
  540.     #declare lf_ave_dist  = 1 / num_arms2
  541.   #end
  542.  
  543.   #declare lf_loc = 0
  544.  
  545.   color_map{
  546.     [0.0          color star_color transmit star_tr ]
  547.     [lf_tmp_width color star_color transmit 1.0     ]
  548.  
  549.     #declare lf_loc = lf_loc +  lf_ave_dist + (rand(star_seed)*2 - 1)*star_rand2*(lf_ave_dist-2*lf_tmp_width)
  550.     #while (lf_loc <(1-2*lf_tmp_width))
  551.       #declare lf_s_color = star_color + star_color_rand * <(rand(star_seed) * 2 - 1),(rand(star_seed) * 2 - 1),(rand(spot_seed) * 2 - 1)>
  552.       [lf_loc - lf_tmp_width  color lf_s_color transmit 1.0    ]
  553.       [lf_loc                 color lf_s_color transmit star_tr]
  554.       [lf_loc + lf_tmp_width  color lf_s_color transmit 1.0    ]
  555.       #declare lf_loc = lf_loc +  lf_ave_dist + (rand(star_seed)*2 - 1)*star_rand2*(lf_ave_dist-2*lf_tmp_width)
  556.     #end
  557.  
  558.     [1-lf_tmp_width color star_color transmit 1.0     ]
  559.     [1.0            color star_color transmit star_tr ]
  560.   }
  561.  
  562.  rotate <90,0,-90>
  563. }
  564. #end
  565.  
  566. #declare lf_PrimaryFlare = pigment {
  567.   wood
  568.   color_map {
  569.      [ 0.0             color source_color*source_bright transmit source_tr ]
  570.      [ source_size     color source_color*glow_bright transmit source_tr   ]
  571.      [ source_size + (glow_size - source_size)*source_fade
  572.                        color glow_color*glow_bright
  573.                        transmit (source_tr+glow_tr)/2 ]
  574.  
  575.      [ glow_size                 color glow_color   transmit glow_tr ]
  576.      [ (glow_size + ring_size)/2 color glow_color   transmit 1       ]
  577.  
  578.      [ (glow_size + ring_size)/2 color ring_color   transmit 1            ]
  579.      [ (ring_size - ring_width * ring_size) color ring_color   transmit 1 ]
  580.      [ ring_size                 color ring_color   transmit ring_tr      ]
  581.      [ (ring_size + ring_width * ring_size) color ring_color   transmit 1 ]
  582.      [ 1 color rgbt <0,0,0,1> ]
  583.   } #ifdef (flare_scallop_wave) #if (flare_scallop_wave = yes) scallop_wave #end #end
  584. }
  585.  
  586. #declare lf_Finish = finish {
  587.   refraction off
  588.   specular 0
  589.   phong 0
  590.   diffuse 0.0
  591.   reflection 0.0
  592.  
  593.   #declare lf_bright = <1,1,1>
  594.   #ifdef (AmbientLight)
  595.     #declare lf_bright = lf_bright / AmbientLight
  596.   #end
  597.   #ifdef (flare_brightness)
  598.     #declare lf_bright = lf_bright * flare_brightness
  599.   #end
  600.  
  601.   ambient lf_bright
  602. }
  603.  
  604. // *****************************************************************
  605. // ** First, make sure the camera is in front of the camera by
  606. //    checking the plane with normal from cam_loc to lookat.
  607. //
  608. //  Plane equation:   a(x-x0) + b(y-y0) + c(z-z0) = 0
  609. //
  610. // *****************************************************************
  611. #ifdef(lookat)
  612.   #declare cam_plane = 1 * vdot(lf_2ctr, lf_2light)
  613. #else
  614.   #declare cam_plane = 1  // assume flare in front of camera if no lookat given
  615. #end
  616.  
  617. #ifndef (lf_visible) #declare lf_visible = 1 #end
  618. #if ((cam_plane < 0) | (no_lens_flare = true))
  619.   #warning "Light is behind camera or behind the planet.  Lens flare not created."
  620.   // *****************************************************************
  621.   // Skip lens flare completely... can have an impact on
  622.   // render speed.
  623.   // *****************************************************************
  624. #else
  625.  
  626. // *****************************************************************
  627. // ********** THE ACTUAL DISCS FOR LENS FLARE **********************
  628. // *****************************************************************
  629.  
  630. #ifndef (lf_flares_drawn) #declare lf_flares_drawn = 0 #end
  631.  
  632. #declare lf_new_disc_size = disc_size + .001 * lf_flares_drawn
  633. disc {
  634.   #declare lf_bound_y = (ring_size*(1+ring_width))/2
  635.   <0,0,0>, z, lf_bound_y
  636.  
  637.   texture {
  638.     // ***************** Primary flare ********************
  639.     pigment {
  640.       lf_PrimaryFlare
  641.     }
  642.     finish { lf_Finish }
  643.   }
  644.   scale main_flare_scale * lf_new_disc_size * flare_size
  645.  
  646.   #if (flare_auto_rotate = false)
  647.     rotate lf_rotate_up
  648.   #else
  649.     rotate lf_rotate_ctr
  650.   #end
  651.   rotate flare_rotate*z
  652.   rotate lf_rotate_x
  653.   rotate lf_rotate_z
  654.  
  655.   #declare lf_dist = 1/( vdot(lf_2light,lf_2ctr)/(vlength(lf_2ctr)*vlength(lf_2light)) )
  656.   translate cam_loc + lf_new_disc_size * vnormalize(-lf_2light)*lf_dist
  657.   no_shadow hollow
  658. }
  659. #declare lf_flares_drawn = lf_flares_drawn + 1
  660.  
  661. #if ((num_arms > 0) | (num_arms2 > 0))
  662.  
  663. #if (star_spread)
  664. #declare lf_new_disc_size = disc_size + .001 * lf_flares_drawn
  665. disc {
  666.   #declare lf_bound_y = max(star_size*3,star_size2*3)/2
  667.   <0,0,0>, z, lf_bound_y
  668.   #if (num_arms > 0)
  669.     texture {
  670.       // ************** Star-type flare *********************
  671.       pigment {
  672.         wood
  673.         pigment_map {
  674.           [ 0.0            lf_StarTex]
  675.           [ star_size      lf_StarTex]
  676.           [ star_size * 3  lf_StarTex transmit 1]
  677.           [ 1              lf_StarTex transmit 1]
  678.         }
  679.       }
  680.       finish { lf_Finish }
  681.     }
  682.   #end
  683.   #if (num_arms2 > 0)
  684.     texture {
  685.       // ************** Star-type2 flare *********************
  686.       pigment {
  687.         wood
  688.         pigment_map {
  689.           [ 0.0             lf_StarTex2]
  690.           [ star_size2      lf_StarTex2]
  691.           [ star_size2 * 3  lf_StarTex2 transmit 1 ]
  692.           [ 1               lf_StarTex2 transmit 1 ]
  693.         }
  694.       }
  695.       finish { lf_Finish }
  696.     }
  697.   #end
  698.  
  699.   scale main_flare_scale * lf_new_disc_size * flare_size
  700.  
  701.   #if (flare_auto_rotate = false)
  702.     rotate lf_rotate_up
  703.   #else
  704.     rotate lf_rotate_ctr
  705.   #end
  706.   rotate flare_rotate*z
  707.   rotate lf_rotate_x
  708.   rotate lf_rotate_z
  709.  
  710.   #declare lf_dist = 1/( vdot(lf_2light,lf_2ctr)/(vlength(lf_2ctr)*vlength(lf_2light)) )
  711.   translate cam_loc + lf_new_disc_size * vnormalize(-lf_2light)*lf_dist
  712.   no_shadow hollow
  713. }
  714. #declare lf_flares_drawn = lf_flares_drawn + 1
  715.  
  716. #else // star_spread
  717.   // **************************************
  718.   // Create a bunch of streaks to simulate
  719.   // the sparkle pattern
  720.   //
  721. #declare lf_tmp_num=2
  722. #while (lf_tmp_num>0)
  723.  
  724.   #if (lf_tmp_num = 2)
  725.   #if (star_mirror)
  726.     #declare lf_num = num_arms / 2
  727.     #declare lf_tmp_width = star_width / num_arms * .25
  728.     #declare lf_ave_ang  = 360 / num_arms // 2
  729.   #else
  730.     #declare lf_num = num_arms
  731.     #declare lf_tmp_width = star_width / num_arms * .25
  732.     #declare lf_ave_ang  = 360 / num_arms
  733.   #end
  734.   #else
  735.   #if (star_mirror)
  736.     #declare lf_num = num_arms2 / 2
  737.     #declare lf_tmp_width = star_width2 / num_arms2 * .25
  738.     #declare lf_ave_ang  = 360 / num_arms2 // 2
  739.   #else
  740.     #declare lf_num = num_arms2
  741.     #declare lf_tmp_width = star_width2 / num_arms2 * .25
  742.     #declare lf_ave_ang  = 360 / num_arms2
  743.   #end
  744.   #end
  745.  
  746.   #while (lf_num > 0)
  747.  
  748.     #if (lf_tmp_num = 2)
  749.     #declare lf_tmp_size = star_size + (rand(star_seed) * 2 - 1) * star_size_rand
  750.     #declare lf_tmp_ang  = lf_num * lf_ave_ang + (rand(star_seed) * 2 - 1) * star_rand * lf_ave_ang
  751.     #declare lf_s_color = star_color + star_color_rand * <(rand(star_seed) * 2 - 1),(rand(star_seed) * 2 - 1),(rand(spot_seed) * 2 - 1)>
  752.     #else
  753.     #declare lf_tmp_size = star_size2 + (rand(star_seed) * 2 - 1) * star_size_rand
  754.     #declare lf_tmp_ang  = lf_num * lf_ave_ang + (rand(star_seed) * 2 - 1) * star_rand2 * lf_ave_ang
  755.     #declare lf_s_color = star_color + star_color_rand * <(rand(star_seed) * 2 - 1),(rand(star_seed) * 2 - 1),(rand(spot_seed) * 2 - 1)>
  756.     #end
  757.  
  758.     #declare lf_new_disc_size = disc_size + .001 * lf_flares_drawn
  759.     disc {
  760.       <0,0,0>, z, 1
  761.       texture {
  762.         pigment {
  763.           wood
  764.           ramp_wave
  765.           color_map{
  766.             [0.0 color lf_s_color transmit star_tr]
  767.             #if (crisp_star=true)
  768.               [1.0 color lf_s_color transmit star_tr]
  769.             #else
  770.               [1.0 color lf_s_color transmit 1.0]
  771.             #end
  772.           }
  773.         }
  774.         finish { lf_Finish }
  775.       }
  776.       
  777.       scale <lf_tmp_size,lf_tmp_width,1> * lf_new_disc_size * flare_size
  778.       #if (star_mirror=false)
  779.         scale <.5,1,1>
  780.         translate <.5,0,0>*lf_tmp_size* lf_new_disc_size.x * flare_size.x
  781.       #end
  782.  
  783.       rotate (lf_tmp_ang + flare_rotate)*z
  784.  
  785.       scale main_flare_scale
  786.  
  787.       #if (flare_auto_rotate = false)
  788.         rotate lf_rotate_up
  789.       #else
  790.         rotate lf_rotate_ctr
  791.       #end
  792.       rotate lf_rotate_x
  793.       rotate lf_rotate_z
  794.  
  795.       #declare lf_dist = 1/( vdot(lf_2light,lf_2ctr)/(vlength(lf_2ctr)*vlength(lf_2light)) )
  796.       translate cam_loc + lf_new_disc_size * vnormalize(-lf_2light)*lf_dist
  797.       no_shadow hollow
  798.     }
  799.     #declare lf_flares_drawn = lf_flares_drawn + 1
  800.     #declare lf_num = lf_num - 1
  801.   #end
  802. #declare lf_tmp_num = lf_tmp_num-1
  803. #end //while
  804.  
  805. #end // star_spread
  806.  
  807.  
  808. #end
  809.  
  810. // ************** streak_a flare *********************
  811. #declare lf_new_disc_size = disc_size + .001 * lf_flares_drawn
  812. #if ((streak_a_size > 0) & (streak_a_tr < 1))
  813.   disc {
  814.     <0,0,0>, z, .5
  815.     texture {
  816.       pigment {
  817.         wood
  818.         color_map {
  819.            [ 0.0  color streak_a_center_color transmit streak_a_tr ]
  820.            [ 1.0  color streak_a_color transmit 1           ]
  821.         }
  822.       }
  823.       finish { lf_Finish }
  824.     }
  825.     scale streak_a_scale * streak_a_size * lf_new_disc_size * flare_size
  826.  
  827.     #if (streak_a_auto_rotate = false)
  828.       rotate lf_rotate_up
  829.     #else
  830.       rotate lf_rotate_ctr
  831.     #end
  832.     rotate streak_a_rotate*z
  833.     rotate lf_rotate_x
  834.     rotate lf_rotate_z
  835.  
  836.     #declare lf_dist = 1/( vdot(lf_2light,lf_2ctr)/(vlength(lf_2ctr)*vlength(lf_2light)) )
  837.     translate cam_loc + lf_new_disc_size * vnormalize(-lf_2light)*lf_dist
  838.     no_shadow hollow
  839.   }
  840.   #declare lf_flares_drawn = lf_flares_drawn + 1
  841. #end
  842.  
  843. // ************** streak_b flare *********************
  844. #declare lf_new_disc_size = disc_size + .001 * lf_flares_drawn
  845. #if ((streak_b_size > 0) & (streak_b_tr < 1))
  846.   disc {
  847.     <0,0,0>, z, .5
  848.     texture {
  849.       pigment {
  850.         wood
  851.         color_map {
  852.            [ 0.0  color streak_b_center_color transmit streak_b_tr ]
  853.            [ 1.0  color streak_b_color transmit 1           ]
  854.         }
  855.       }
  856.       finish { lf_Finish }
  857.     }
  858.     scale streak_b_scale * streak_b_size * lf_new_disc_size * flare_size
  859.  
  860.     #if (streak_b_auto_rotate = false)
  861.       rotate lf_rotate_up
  862.     #else
  863.       rotate lf_rotate_ctr
  864.     #end
  865.     rotate streak_b_rotate*z
  866.     rotate lf_rotate_x
  867.     rotate lf_rotate_z
  868.  
  869.     #declare lf_dist = 1/( vdot(lf_2light,lf_2ctr)/(vlength(lf_2ctr)*vlength(lf_2light)) )
  870.     translate cam_loc + lf_new_disc_size * vnormalize(-lf_2light)*lf_dist
  871.     no_shadow hollow
  872.   }
  873.   #declare lf_flares_drawn = lf_flares_drawn + 1
  874. #end
  875.  
  876. // ************** big_glow flare *********************
  877. #declare lf_new_disc_size = disc_size + .001 * lf_flares_drawn
  878. #if ((big_glow_size > 0) & (big_glow_tr < 1))
  879.   disc {
  880.     #declare lf_bound_y = big_glow_size/2
  881.     <0,0,0>, z, lf_bound_y
  882.     texture {
  883.       pigment {
  884.         wood
  885.         color_map {
  886.            [ 0.0           color big_glow_color transmit big_glow_tr ]
  887.            [ big_glow_size color big_glow_color transmit 1           ]
  888.            [ 1 color       rgbt <0,0,0,1> ]
  889.         }
  890.       }
  891.       finish { lf_Finish }
  892.     }
  893.     scale big_glow_scale * lf_new_disc_size * flare_size
  894.  
  895.     #if (flare_auto_rotate = false)
  896.       rotate lf_rotate_up
  897.     #else
  898.       rotate lf_rotate_ctr
  899.     #end
  900.     rotate lf_rotate_x
  901.     rotate lf_rotate_z
  902.  
  903.     #declare lf_dist = 1/( vdot(lf_2light,lf_2ctr)/(vlength(lf_2ctr)*vlength(lf_2light)) )
  904.     translate cam_loc + lf_new_disc_size * vnormalize(-lf_2light)*lf_dist
  905.     no_shadow hollow
  906.   }
  907.   #declare lf_flares_drawn = lf_flares_drawn + 1
  908. #end
  909.  
  910. //  *********************************************************************
  911. //  *********************  Multiple lens flare spots ********************
  912. //  *********************************************************************
  913. #declare num_spots = num_spots + skip_spots
  914. #declare opposite_spots = opposite_spots + skip_spots
  915.  
  916. #while (num_spots > skip_spots)
  917.   // *****************************************************************
  918.   // ** randomly shift various attributes
  919.   // *****************************************************************
  920.   #declare lf_s_size  = spot_size + (rand(spot_seed) * 2 - 1) * spot_size_rand
  921.   #declare lf_s_dist  = (rand(spot_seed) * 2 - 1) * spot_dist_rand
  922.   #declare lf_s_color = spot_color + spot_color_rand * <(rand(spot_seed) * 2 - 1),(rand(spot_seed) * 2 - 1),(rand(spot_seed) * 2 - 1)>
  923.   #declare lf_d_size  = dot_size + (rand(spot_seed) * 2 - 1) * dot_size_rand
  924.   #declare lf_d_color = dot_color + dot_color_rand * <(rand(spot_seed) * 2 - 1),(rand(spot_seed) * 2 - 1),(rand(spot_seed) * 2 - 1)>
  925.  
  926.   #declare lf_pentagon = false
  927.   
  928.   #declare lf_is_dot = rand(spot_seed)
  929.  
  930.   #switch (lf_is_dot)
  931.   #range (0,percent_dots)
  932.     #declare lf_SpotPigment = pigment {
  933.       wood
  934.       #declare tmp_tr = dot_tr + (1-dot_tr)*spot_fade_amount*(num_spots - skip_spots)
  935.       color_map {
  936.          [ 0.0                        color lf_d_color transmit tmp_tr         ]
  937.          [ lf_d_size / 1.2            color lf_d_color transmit (1+tmp_tr)*.53 ]
  938.          [ lf_d_size                  color lf_d_color transmit 1              ]
  939.          [ 1 color rgbt <0,0,0,1> ]
  940.       }
  941.     }
  942.     #declare lf_bound_y = lf_d_size/2
  943.   #break
  944.  
  945.   #range (percent_dots,percent_dots+percent_hex)
  946.     #declare tmp_tr = spot_tr + (1-spot_tr)*spot_fade_amount*(num_spots - skip_spots)
  947.     #declare lf_SpotPigment = pigment{hexagon lf_s_color transmit tmp_tr,rgbt<1,1,1,1>,rgbt<1,1,1,1> rotate 90*x scale .5*lf_s_size}
  948.     #declare lf_bound_y = lf_s_size/2
  949.   #break
  950.  
  951.   #range (percent_dots+percent_hex,percent_dots+percent_hex+percent_pent)
  952.     #declare lf_pentagon = true
  953.     #declare tmp_tr = spot_tr + (1-spot_tr)*spot_fade_amount*(num_spots - skip_spots)
  954.     #declare lf_SpotPigment = pigment{color lf_s_color transmit tmp_tr}
  955.     #declare lf_bound_y = lf_s_size/2
  956.   #break
  957.  
  958.   #else
  959.     #declare lf_SpotPigment = pigment {
  960.       wood
  961.       #declare tmp_tr = spot_tr + (1-spot_tr)*spot_fade_amount*(num_spots - skip_spots)
  962.       color_map {
  963.          [ 0.0                       color lf_s_color transmit 1              ]
  964.          [ lf_s_size / 1.8           color lf_s_color transmit (1+tmp_tr)*.53 ]
  965.          [ lf_s_size                 color lf_s_color transmit tmp_tr         ]
  966.          [ lf_s_size +.1 * lf_s_size color lf_s_color transmit 1              ]
  967.          [ 1 color rgbt <0,0,0,1> ]
  968.       }
  969.     }
  970.     #declare lf_bound_y = lf_s_size*1.1/2
  971.   #end
  972.  
  973.   // ************* Arm pointing toward middle ************
  974.   // *****************************************************
  975.   #declare lf_new_disc_size = disc_size + .001 * lf_flares_drawn
  976.  
  977.   #if (lf_pentagon=false)
  978.   disc {
  979.     <0,0,0>, z, lf_bound_y
  980.   #else
  981.   polygon {
  982.     6,
  983.     <0,-1>
  984.     < cos(radians(18)),-sin(radians(18))>,
  985.     < cos(radians(54)), sin(radians(54))>,
  986.     <-cos(radians(54)), sin(radians(54))>,
  987.     <-cos(radians(18)),-sin(radians(18))>,
  988.     <0,-1>
  989.     scale lf_s_size
  990.   #end
  991.     texture {
  992.       pigment { lf_SpotPigment }
  993.       finish { lf_Finish }
  994.     }
  995.     // *****************************************************************
  996.     // ** calculate the apparant position of the flare spot
  997.     // *****************************************************************
  998.     #declare lf_2spot = lf_2light + (lf_newctr - lf_2light) * (spot_dist * pow(num_spots, spot_dist_pwr) + lf_s_dist)
  999.  
  1000.     scale lf_new_disc_size * flare_size
  1001.  
  1002.     #if (spots_auto_rotate=true)
  1003.       rotate lf_rotate_ctr
  1004.     #else
  1005.       rotate lf_rotate_up
  1006.     #end
  1007.     rotate lf_rotate_x
  1008.     rotate lf_rotate_z
  1009.  
  1010.     #declare lf_dist = 1/( vdot(lf_2spot,lf_2ctr)/(vlength(lf_2ctr)*vlength(lf_2spot)) )
  1011.     translate cam_loc + lf_new_disc_size * vnormalize(-lf_2spot)*lf_dist
  1012.     no_shadow hollow
  1013.   }
  1014.   #declare lf_flares_drawn = lf_flares_drawn + 1
  1015.  
  1016. #if (num_spots <= opposite_spots) // !*!*!*!*!*!*!*!*!*!
  1017.   // *****************************************************************
  1018.   // ** randomly shift various attributes - again
  1019.   // *****************************************************************
  1020.   #declare lf_s_size  = spot_size + (rand(spot_seed) * 2 - 1) * spot_size_rand
  1021.   #declare lf_s_dist  = (rand(spot_seed) * 2 - 1) * spot_dist_rand
  1022.   #declare lf_s_color = spot_color + spot_color_rand * <(rand(spot_seed) * 2 - 1),(rand(spot_seed) * 2 - 1),(rand(spot_seed) * 2 - 1)>
  1023.   #declare lf_d_size  = dot_size + (rand(spot_seed) * 2 - 1) * dot_size_rand
  1024.   #declare lf_d_color = dot_color + dot_color_rand * <(rand(spot_seed) * 2 - 1),(rand(spot_seed) * 2 - 1),(rand(spot_seed) * 2 - 1)>
  1025.  
  1026.   #declare lf_pentagon = false
  1027.   
  1028.   #declare lf_is_dot = rand(spot_seed)
  1029.  
  1030.   #switch (lf_is_dot)
  1031.   #range (0,percent_dots)
  1032.     #declare lf_SpotPigment = pigment {
  1033.       wood
  1034.       #declare tmp_tr = dot_tr + (1-dot_tr)*spot_fade_amount*(num_spots - skip_spots)
  1035.       color_map {
  1036.          [ 0.0                        color lf_d_color transmit tmp_tr         ]
  1037.          [ lf_d_size / 1.2            color lf_d_color transmit (1+tmp_tr)*.53 ]
  1038.          [ lf_d_size                  color lf_d_color transmit 1              ]
  1039.          [ 1 color rgbt <0,0,0,1> ]
  1040.       }
  1041.     }
  1042.     #declare lf_bound_y = lf_d_size/2
  1043.   #break
  1044.  
  1045.   #range (percent_dots,percent_dots+percent_hex)
  1046.     #declare tmp_tr = spot_tr + (1-spot_tr)*spot_fade_amount*(num_spots - skip_spots)
  1047.     #declare lf_SpotPigment = pigment{hexagon lf_s_color transmit tmp_tr,rgbt<1,1,1,1>,rgbt<1,1,1,1> rotate 90*x scale .5*lf_s_size}
  1048.     #declare lf_bound_y = lf_s_size/2
  1049.   #break
  1050.  
  1051.   #range (percent_dots+percent_hex,percent_dots+percent_hex+percent_pent)
  1052.     #declare lf_pentagon = true
  1053.     #declare tmp_tr = spot_tr + (1-spot_tr)*spot_fade_amount*(num_spots - skip_spots)
  1054.     #declare lf_SpotPigment = pigment{color lf_s_color transmit tmp_tr}
  1055.     #declare lf_bound_y = lf_s_size/2
  1056.   #break
  1057.  
  1058.   #else
  1059.     #declare lf_SpotPigment = pigment {
  1060.       wood
  1061.       #declare tmp_tr = spot_tr + (1-spot_tr)*spot_fade_amount*(num_spots - skip_spots)
  1062.       color_map {
  1063.          [ 0.0                       color lf_s_color transmit 1              ]
  1064.          [ lf_s_size / 1.8           color lf_s_color transmit (1+tmp_tr)*.53 ]
  1065.          [ lf_s_size                 color lf_s_color transmit tmp_tr         ]
  1066.          [ lf_s_size +.1 * lf_s_size color lf_s_color transmit 1              ]
  1067.          [ 1 color rgbt <0,0,0,1> ]
  1068.       }
  1069.     }
  1070.     #declare lf_bound_y = lf_s_size*1.1/2
  1071.   #end
  1072.  
  1073.   // ************* Arm pointing away *********************
  1074.   // *****************************************************
  1075.   #declare lf_new_disc_size = disc_size + .001 * lf_flares_drawn
  1076.  
  1077.   #if (lf_pentagon=false)
  1078.   disc {
  1079.     <0,0,0>, z, lf_bound_y
  1080.   #else
  1081.   polygon {
  1082.     6,
  1083.     <0,-1>
  1084.     < cos(radians(18)),-sin(radians(18))>,
  1085.     < cos(radians(54)), sin(radians(54))>,
  1086.     <-cos(radians(54)), sin(radians(54))>,
  1087.     <-cos(radians(18)),-sin(radians(18))>,
  1088.     <0,-1>
  1089.     scale lf_s_size
  1090.   #end
  1091.     texture {
  1092.       pigment { lf_SpotPigment }
  1093.       finish { lf_Finish }
  1094.     }
  1095.     // *****************************************************************
  1096.     // ** calculate the apparant position of the flare spot
  1097.     // *****************************************************************
  1098.     #declare lf_2spot = lf_2light - (lf_newctr - lf_2light) * (spot_dist * pow(num_spots, spot_dist_pwr) + lf_s_dist)
  1099.  
  1100.     scale lf_new_disc_size * flare_size
  1101.  
  1102.     #if (spots_auto_rotate=true)
  1103.       rotate lf_rotate_ctr+180*z
  1104.     #else
  1105.       rotate lf_rotate_up
  1106.     #end
  1107.     rotate lf_rotate_x
  1108.     rotate lf_rotate_z
  1109.  
  1110.     #declare lf_dist = 1/( vdot(lf_2spot,lf_2ctr)/(vlength(lf_2ctr)*vlength(lf_2spot)) )
  1111.     translate cam_loc + lf_new_disc_size * vnormalize(-lf_2spot)*lf_dist
  1112.     no_shadow hollow
  1113.   }
  1114.   #declare lf_flares_drawn = lf_flares_drawn + 1
  1115.  
  1116.   #declare opposite_spots = opposite_spots - 1
  1117. #end
  1118.  
  1119.   #declare num_spots = num_spots - 1
  1120. #end
  1121.  
  1122. #ifdef (lf_50mm_spots)  #if (lf_50mm_spots = true)
  1123.   #declare lf_new_disc_size = disc_size + .001 * lf_flares_drawn
  1124.   disc {
  1125.     #declare lf_bound_y = ring_size*2.30/2
  1126.     <0,0,0>, z, lf_bound_y
  1127.     texture {
  1128.       // *****************************************************************
  1129.       // ***************** 50-300mm xtra large spot **********************
  1130.       // *****************************************************************
  1131.       pigment {
  1132.         wood
  1133.         color_map {
  1134.            [ 0.0              color transmit 1                ]
  1135.            [ ring_size*2      color <1,1,.7> transmit 1       ]
  1136.            [ ring_size*2.15   color <1,1,.7> transmit spot_tr ]
  1137.            [ ring_size*2.15   color <.8,.8,1> transmit spot_tr]
  1138.            [ ring_size*2.30   color <.8,.8,1> transmit 1      ]
  1139.            [ 1 color rgbt <0,0,0,1> ]
  1140.         }
  1141.       }
  1142.       finish { lf_Finish }
  1143.     }
  1144.     // *****************************************************************
  1145.     // ** calculate the apparant position of the flare spot
  1146.     // *****************************************************************
  1147.     #declare lf_2spot = lf_2light + (lf_newctr - lf_2light) * 2
  1148.  
  1149.     scale lf_new_disc_size * flare_size
  1150.  
  1151.     #if (flare_auto_rotate = false)
  1152.       rotate lf_rotate_up
  1153.     #else
  1154.       rotate lf_rotate_ctr
  1155.     #end
  1156.     rotate lf_rotate_x
  1157.     rotate lf_rotate_z
  1158.  
  1159.     #declare lf_dist = 1/( vdot(lf_2spot,lf_2ctr)/(vlength(lf_2ctr)*vlength(lf_2spot)) )
  1160.     translate cam_loc + lf_new_disc_size * vnormalize(-lf_2spot)*lf_dist
  1161.     no_shadow hollow
  1162.   }
  1163.   #declare lf_flares_drawn = lf_flares_drawn + 1
  1164. #end #end
  1165.  
  1166. #ifdef (lf_35mm_spots)  #if (lf_35mm_spots = true)
  1167.   #declare lf_new_disc_size = disc_size + .001 * lf_flares_drawn
  1168.   disc {
  1169.     #declare lf_bound_y = ring_size*2.15/2
  1170.     <0,0,0>, z, lf_bound_y
  1171.     texture {
  1172.       // *****************************************************************
  1173.       // ***************** 35mm xtra large spot **************************
  1174.       // *****************************************************************
  1175.       pigment {
  1176.         wood
  1177.         color_map {
  1178.            [ 0.0              color <.8,1,.8> transmit spot_tr*.95     ]
  1179.            [ ring_size/3      color <.8,1,.8> transmit spot_tr        ]
  1180.            [ ring_size*1.5    color <.8,1,.8> transmit (spot_tr+1)/2  ]
  1181.            [ ring_size*2      color <.8,1,.8> transmit spot_tr        ]
  1182.            [ ring_size*2.15   color <.8,1,.8> transmit 1              ]
  1183.            [ 1 color rgbt <0,0,0,1> ]
  1184.         }
  1185.       }
  1186.       finish { lf_Finish }
  1187.     }
  1188.     // *****************************************************************
  1189.     // ** calculate the apparant position of the flare spot
  1190.     // *****************************************************************
  1191.     #declare lf_2spot = lf_2light + (lf_newctr - lf_2light) * 2
  1192.  
  1193.     scale lf_new_disc_size * flare_size
  1194.  
  1195.     #if (flare_auto_rotate = false)
  1196.       rotate lf_rotate_up
  1197.     #else
  1198.       rotate lf_rotate_ctr
  1199.     #end
  1200.     rotate lf_rotate_x
  1201.     rotate lf_rotate_z
  1202.  
  1203.     #declare lf_dist = 1/( vdot(lf_2spot,lf_2ctr)/(vlength(lf_2ctr)*vlength(lf_2spot)) )
  1204.     translate cam_loc + lf_new_disc_size * vnormalize(-lf_2spot)*lf_dist
  1205.     no_shadow hollow
  1206.   }
  1207.   #declare lf_flares_drawn = lf_flares_drawn + 1
  1208. #end #end
  1209.  
  1210. #ifdef (lf_space_spots)  #if (lf_space_spots = true)
  1211.   #declare lf_new_disc_size = disc_size + .001 * lf_flares_drawn
  1212.   disc {
  1213.     #declare lf_bound_y = ring_size*2.30/2
  1214.     <0,0,0>, z, lf_bound_y
  1215.     texture {
  1216.       // *****************************************************************
  1217.       // ***************** anamorphic "shadow" 1    **********************
  1218.       // *****************************************************************
  1219.       pigment {
  1220.         wood
  1221.         color_map {
  1222.            [ 0.0              color transmit 1 ]
  1223.            [ ring_size        color ring_color transmit 1      ]
  1224.            [ ring_size*1.15   color ring_color transmit spot_tr*.98]
  1225.            [ ring_size*1.15   color ring_color transmit spot_tr*.98]
  1226.            [ ring_size*1.30   color ring_color transmit 1      ]
  1227.            [ 1 color rgbt <0,0,0,1> ]
  1228.         }
  1229.       }
  1230.       finish { lf_Finish }
  1231.     }
  1232.     // *****************************************************************
  1233.     // ** calculate the apparant position of the flare spot
  1234.     // *****************************************************************
  1235.     #declare lf_2spot = lf_2light + (lf_newctr - lf_2light) * 2
  1236.  
  1237.     scale main_flare_scale * lf_new_disc_size * flare_size
  1238.  
  1239.     #if (flare_auto_rotate = false)
  1240.       rotate lf_rotate_up
  1241.     #else
  1242.       rotate lf_rotate_ctr
  1243.     #end
  1244.     rotate lf_rotate_x
  1245.     rotate lf_rotate_z
  1246.  
  1247.     #declare lf_dist = 1/( vdot(lf_2spot,lf_2ctr)/(vlength(lf_2ctr)*vlength(lf_2spot)) )
  1248.     translate cam_loc + lf_new_disc_size * vnormalize(-lf_2spot)*lf_dist
  1249.     no_shadow hollow
  1250.   }
  1251.   #declare lf_flares_drawn = lf_flares_drawn + 1
  1252.  
  1253.   #declare lf_new_disc_size = disc_size + .001 * lf_flares_drawn
  1254.   disc {
  1255.     #declare lf_bound_y = ring_size*2.30/2
  1256.     <0,0,0>, z, lf_bound_y
  1257.     texture {
  1258.       // *****************************************************************
  1259.       // ***************** anamorphic "shadow" 2    **********************
  1260.       // *****************************************************************
  1261.       pigment {
  1262.         wood
  1263.         color_map {
  1264.            [ 0.0              color transmit 1 ]
  1265.            [ ring_size        color glow_color transmit 1      ]
  1266.            [ ring_size*1.15   color glow_color transmit spot_tr*.98]
  1267.            [ ring_size*1.15   color glow_color transmit spot_tr*.98]
  1268.            [ ring_size*1.30   color glow_color transmit 1      ]
  1269.            [ 1 color rgbt <0,0,0,1> ]
  1270.         }
  1271.       }
  1272.       finish { lf_Finish }
  1273.     }
  1274.     // *****************************************************************
  1275.     // ** calculate the apparant position of the flare spot
  1276.     // *****************************************************************
  1277.     #declare lf_2spot = lf_2light + (lf_newctr - lf_2light) * 2.02
  1278.  
  1279.     scale main_flare_scale*.8 * lf_new_disc_size * flare_size
  1280.  
  1281.     #if (flare_auto_rotate = false)
  1282.       rotate lf_rotate_up
  1283.     #else
  1284.       rotate lf_rotate_ctr
  1285.     #end
  1286.     rotate lf_rotate_x
  1287.     rotate lf_rotate_z
  1288.  
  1289.     #declare lf_dist = 1/( vdot(lf_2spot,lf_2ctr)/(vlength(lf_2ctr)*vlength(lf_2spot)) )
  1290.     translate cam_loc + lf_new_disc_size * vnormalize(-lf_2spot)*lf_dist
  1291.     no_shadow hollow
  1292.   }
  1293.   #declare lf_flares_drawn = lf_flares_drawn + 1
  1294.  
  1295.   #declare lf_new_disc_size = disc_size + .001 * lf_flares_drawn
  1296.   disc {
  1297.     <0,0,0>, z, .5
  1298.     texture {
  1299.       // *****************************************************************
  1300.       // ***************** anamorphic "shadow" 3    **********************
  1301.       // *****************************************************************
  1302.       pigment {
  1303.         wood
  1304.         color_map {
  1305.            [ 0.0           color streak_a_color transmit spot_tr*.9 ]
  1306.            [ 1.0  color streak_a_color transmit 1          ]
  1307.         }
  1308.       }
  1309.       finish { lf_Finish }
  1310.     }
  1311.     // *****************************************************************
  1312.     // ** calculate the apparant position of the flare spot
  1313.     // *****************************************************************
  1314.     #declare lf_2spot = lf_2light + (lf_newctr - lf_2light) * 1.8
  1315.  
  1316.     scale streak_a_scale*<.2,1,1>* streak_a_size * lf_new_disc_size * flare_size
  1317.  
  1318.     #if (streak_a_auto_rotate = false)
  1319.       rotate lf_rotate_up
  1320.     #else
  1321.       rotate lf_rotate_ctr
  1322.     #end
  1323.     rotate streak_a_rotate*z
  1324.     rotate lf_rotate_x
  1325.     rotate lf_rotate_z
  1326.  
  1327.     #declare lf_dist = 1/( vdot(lf_2spot,lf_2ctr)/(vlength(lf_2ctr)*vlength(lf_2spot)) )
  1328.     translate cam_loc + lf_new_disc_size * vnormalize(-lf_2spot)*lf_dist
  1329.     no_shadow hollow
  1330.   }
  1331. #end #end
  1332.  
  1333. #ifdef (lf_camcorder_spots)  #if (lf_camcorder_spots = true)
  1334.   #declare lf_new_disc_size = disc_size + .001 * lf_flares_drawn
  1335.   disc {
  1336.     #declare lf_bound_y = ring_size*1.15*1.5/2
  1337.     <0,0,0>, z, lf_bound_y
  1338.     texture {
  1339.       // *****************************************************************
  1340.       // ***************** camcorder xtra large spot *********************
  1341.       // *****************************************************************
  1342.       pigment {
  1343.         wood
  1344.         color_map {
  1345.            [ 0.0              color <.5,1,.9> transmit spot_tr]
  1346.            [ ring_size*0.90*1.5   color <.5,1,.9> transmit .95         ]
  1347.            [ ring_size*1.15*1.6   color <0,0,0> transmit 1          ]
  1348.            [ 1 color rgbt <0,0,0,1> ]
  1349.         }
  1350.       }
  1351.       finish { lf_Finish }
  1352.     }
  1353.     // *****************************************************************
  1354.     // ** calculate the apparant position of the flare spot
  1355.     // *****************************************************************
  1356.     #declare lf_2spot = lf_2light + (lf_newctr - lf_2light) * 2
  1357.  
  1358.     scale lf_new_disc_size * flare_size
  1359.  
  1360.     #if (flare_auto_rotate = false)
  1361.       rotate lf_rotate_up
  1362.     #else
  1363.       rotate lf_rotate_ctr
  1364.     #end
  1365.     rotate lf_rotate_x
  1366.     rotate lf_rotate_z
  1367.  
  1368.     #declare lf_dist = 1/( vdot(lf_2spot,lf_2ctr)/(vlength(lf_2ctr)*vlength(lf_2spot)) )
  1369.     translate cam_loc + lf_new_disc_size * vnormalize(-lf_2spot)*lf_dist
  1370.     no_shadow hollow
  1371.   }
  1372.   #declare lf_flares_drawn = lf_flares_drawn + 1
  1373.  
  1374.   #declare lf_new_disc_size = disc_size + .001 * lf_flares_drawn
  1375.   disc {
  1376.     #declare lf_bound_y = ring_size*0.9/2
  1377.     <0,0,0>, z, lf_bound_y
  1378.     texture {
  1379.       // *****************************************************************
  1380.       // ***************** camcorder xtra large spot *********************
  1381.       // *****************************************************************
  1382.       pigment {
  1383.         wood
  1384.         color_map {
  1385.            [ 0.0              color <1,.5,.5> transmit 1          ]
  1386.            [ ring_size*0.65   color <1,.5,.5> transmit .99        ]
  1387.            [ ring_size*0.85   color <1,.5,.5> transmit spot_tr]
  1388.            [ ring_size*0.90   color <1,.5,.5> transmit 1          ]
  1389.            [ 1 color rgbt <0,0,0,1> ]
  1390.         }
  1391.       }
  1392.       finish { lf_Finish }
  1393.     }
  1394.     // *****************************************************************
  1395.     // ** calculate the apparant position of the flare spot
  1396.     // *****************************************************************
  1397.     #declare lf_2spot = lf_2light + (lf_newctr - lf_2light) * 1.8
  1398.  
  1399.     scale lf_new_disc_size * flare_size
  1400.  
  1401.     #if (flare_auto_rotate = false)
  1402.       rotate lf_rotate_up
  1403.     #else
  1404.       rotate lf_rotate_ctr
  1405.     #end
  1406.     rotate lf_rotate_x
  1407.     rotate lf_rotate_z
  1408.  
  1409.     #declare lf_dist = 1/( vdot(lf_2spot,lf_2ctr)/(vlength(lf_2ctr)*vlength(lf_2spot)) )
  1410.     translate cam_loc + lf_new_disc_size * vnormalize(-lf_2spot)*lf_dist
  1411.     no_shadow hollow
  1412.   }
  1413.   #declare lf_flares_drawn = lf_flares_drawn + 1
  1414. #end #end
  1415.  
  1416.  
  1417. #end  // if light was behind camera, lens flare was skipped.
  1418.  
  1419. #end  // if necessary items weren't defined, the lens flare was skipped.
  1420.  
  1421.